define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'courses/courses/index' + location.search,
                    add_url: 'courses/courses/add',
                    edit_url: 'courses/courses/edit',
                    del_url: 'courses/courses/del',
                    multi_url: 'courses/courses/multi',
                    import_url: 'courses/courses/import',
                    table: 'courses_courses',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                // pk: 'id',
                // sortName: 'id',
                // fixedColumns: true,
                // fixedRightNumber: 1,
                pk: 'id',
                sortName: 'id',
                sortOrder: "desc",
                search: false,
                commonSearch: true,
                showExport: false,
                showToggle: false,
                showSearchButton: true,
                searchFormVisible: true,
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'courses_name', title: __('Courses_name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'category.name', title: __('Category.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'area', title: __('行业/专业/级别'), operate: 'like', searchList: function (column) {
                                return Template('categorytpl', {});
                            }
                        },
                        {field: 'userteacher.name', title: __('老师'), operate: 'LIKE'},
                        // {field: 'admin_id', title: __('Admin_id'), visible: false},



                        // {field: 'category.name', title: __('课程名称'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        // {field: 'pid', title: __('Pid'), visible: false},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'sales_num', title: __('Sales_num')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'type', title: __('Type'), searchList: {"视频":__('视频'),"图文":__('图文')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [

                                {
                                    name: 'parent',
                                    text: __('查看课程'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                      url:'courses/catalogue?courses_courses_id={id}',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.type== '视频'){
                                            return true;//显示
                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },
                                {
                                    name: 'parent',
                                    text: __('查看课程'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url:'courses/articlecatalogue?courses_courses_id={id}',
                                    visible:function(row){//判断显示隐藏 只有状态为待审核时展示操作按钮
                                        if(row.type== '图文'){
                                            return true;//显示
                                        }else{
                                            return false;//隐藏
                                        }
                                    },

                                    refresh:true
                                },


                            ],

                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
